package com.compty.paint.manager;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.compty.core.hibernate.HibernateEntityDao;
import com.compty.core.page.Page;
import com.compty.paint.domain.Advertisement;
import com.compty.paint.domain.AuditState;
import com.compty.paint.util.Constants;

/**
 * @Todo:广告管理
 * @author: zhuqh
 * @CreateTime:2011-9-16 上午09:23:24
 */
public class AdvertisementManager extends HibernateEntityDao<Advertisement>{
	
	private AuditStateManager auditStateManager;

	/**
	 * @param curPage 当前页码
	 * @param pageSize 页码大小
	 * @param channelID 频道ID
	 */
	public Page findByPage(Integer curPage, int pageSize,String channelID) {
		Criteria criteria = createCriteria();
		criteria.addOrder(Order.desc("id"));
		
        AuditState auditState = auditStateManager.findUniqueBy("english_name", Constants.Audit_State_Pass);  //审核状态通过
        criteria = criteria.add(Restrictions.eq("auditState", auditState)); 
        
        if( channelID != null && !"".equals(channelID)){
            criteria = criteria.add(Restrictions.eq("channelID", channelID)); 
        }

		return super.pagedQuery(criteria, curPage,pageSize);
	}


	public void setAuditStateManager(AuditStateManager auditStateManager) {
		this.auditStateManager = auditStateManager;
	}
}
